IPython Notebook

IPython notebook is a web-based interactive environment that combines code execution, text, JavaScript/HTML, equations, figures, and videos into a single document. The notebooks are normal files that can be shared with friends and converted to other formats such as HTML or PDF.

IPython notebook is an IPython frontend. IPython provides extensions to the Python programming language that makes working interactively convenient and efficient. These extensions are implemented in the IPython Kernel and are available in all of the IPython Frontends (Notebook, Terminal, Console and Qt Console) when running the kernel.

IPython Notebook Components

There are two major components to Ipython Notebook:

  1. A web application: a browser-based tool for interactive authoring of documents which combine explanatory text, mathematics, computations and their rich media output.

  2. Notebook documents: a representation of all content visible in the web application, including inputs and outputs of the computations, explanatory text, mathematics, images, and rich media representations of objects. Documents are stored in JSON format.

Installing IPython Notebook

If you're using OS X or Windows, it is recommended that you download and install Anaconda, which is a free bundled installer of Python together with many other useful tools (including IPython Notebook.)

Anaconda comes with its own version of Python 2.7, IPython Notebook, plus other libraries like matplotlib and a package manager ("conda") that you can use to install other packages or other Python versions.

https://store.continuum.io/cshop/anaconda/

Launching Ipython Notebook

For Mac and Linux users, open up your terminal. Windows users need to open up their Command Prompt. Change directories in the terminal (using the cd command) to the working directory where you want to store your IPython Notebook data. Then type: $ ipython notebook

It may take a minute or two to set itself up, but eventually IPython Notebook will open in your default web browser. If your browser does not launch, you can type the url that is shown after you enter the ipython notebook command.

Running Code


In [ ]:
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0, 3*np.pi, 500)
plt.plot(x, np.sin(x**2))
plt.title('A simple chirp');

Images


In [ ]:
from IPython.display import Image
Image(url='http://python.org/images/python-logo.gif')

Video


In [ ]:
from IPython.display import YouTubeVideo
# A talk about IPython at Sage Days at U. Washington, Seattle.
# Video credit: William Stein.
YouTubeVideo('1j_HxD4iLn8')

HTML

Header 1 Header 2
row 1, cell 1 row 1, cell 2
row 2, cell 1 row 2, cell 2

External Site


In [ ]:
# Import wikipedia's featured article
from IPython.display import HTML
HTML('<iframe src=http://en.mobile.wikipedia.org/?useformat=mobile width=700 height=350></iframe>')

LaTex

Ipython notebook supports the display of mathematical expressions typeset in LaTeX, which is rendered in the browser thanks to the MathJax library.

MathJax is an open source JavaScript display engine for mathematics that works in all browsers.


In [ ]:
from IPython.display import Math
Math(r'F(k) = \int_{-\infty}^{\infty} f(x) e^{2\pi i k} dx')

References


In [ ]: